home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieOFDb.py < prev    next >
Text File  |  2008-11-17  |  9KB  |  328 lines

  1. # -*- coding: UTF-8 -*-
  2.  
  3. __revision__ = '$Id$'
  4.  
  5. # Written by Christian Sagmueller <christian@sagmueller.net>
  6. # based on PluginMovieIMDB.py, Copyright (c) 2005 Vasco Nunes
  7. # You may use and distribute this software under the terms of the
  8. # GNU General Public License, version 2 or later
  9.  
  10. import gutils
  11. import movie,string,re
  12.  
  13. plugin_name = "OFDb"
  14. plugin_description = "Online-Filmdatenbank"
  15. plugin_url = "www.ofdb.de"
  16. plugin_language = _("German")
  17. plugin_author = "Christian Sagmueller, Jessica Katharina Parth"
  18. plugin_author_email = "Jessica.K.P@women-at-work.org"
  19. plugin_version = "0.9"
  20.  
  21. class Plugin(movie.Movie):
  22.     def __init__(self, id):
  23.         self.encode='utf-8'
  24.         self.movie_id = id
  25.         self.url = "http://www.ofdb.de/%s" % str(self.movie_id)
  26.  
  27.     def initialize(self):
  28.         # OFDb didn't provide the runtime, studio and classification but it provide a link to the german imdb entry
  29.         # lets use the imdb page, why not
  30.         imdb_nr = gutils.trim(self.page, 'http://german.imdb.com/Title?', '"')
  31.         if imdb_nr != '':
  32.             self.imdb_page = self.open_page(url='http://german.imdb.com/Title?' + imdb_nr)
  33.         else:
  34.             self.imdb_page = ''
  35.  
  36.     def get_image(self):
  37.         self.image_url = "http://img.ofdb.de/film/" + gutils.trim(self.page, 'img src="http://img.ofdb.de/film/', '"' )
  38.         
  39.     def get_o_title(self):
  40.         self.o_title = gutils.clean(gutils.trim(self.page, 'Originaltitel:', '</tr>'))
  41.         if self.o_title == '':
  42.             self.o_title = string.replace(self.o_title, ' ', '' )
  43.  
  44.     def get_title(self):
  45.         self.title = gutils.trim(self.page,'size="3"><b>','<')
  46.  
  47.     def get_director(self):
  48.         self.director = gutils.trim(self.page,"Regie:","</a><br>")
  49.  
  50.     def get_plot(self):
  51.         storyid = self.regextrim(self.page, '<a href="plot/', '(">|[&])')
  52.         if not storyid is None:
  53.             story_page = self.open_page(url="http://www.ofdb.de/plot/%s" % (storyid))
  54.         self.plot = gutils.trim(story_page, "</b><br><br>","</")
  55.  
  56.     def get_year(self):
  57.         self.year = gutils.trim(self.page,"Erscheinungsjahr:","</a>")
  58.         self.year = gutils.strip_tags(self.year)
  59.  
  60.     def get_runtime(self):
  61.         # from imdb
  62.         self.runtime = gutils.trim(self.imdb_page, '<h5>Länge:</h5>', ' Min')
  63.  
  64.     def get_genre(self):
  65.         self.genre = gutils.trim(self.page,"Genre(s):","</table>")
  66.         self.genre = string.replace(self.genre, "<br>", ", ")
  67.         self.genre = gutils.strip_tags(self.genre)
  68.         self.genre = string.replace(self.genre, "/", ", ")
  69.         self.genre = gutils.clean(self.genre)
  70.         self.genre = self.genre[0:-1]
  71.  
  72.     def get_cast(self):
  73.         self.cast = ''
  74.         movie_id_elements = string.split(self.movie_id, ',')
  75.         movie_id_elements[0] = string.replace(movie_id_elements[0], "film/", "")
  76.         cast_page = self.open_page(url="http://www.ofdb.de/view.php?page=film_detail&fid=%s" % str(movie_id_elements[0]) )
  77.         self.cast = gutils.trim(cast_page, 'Darsteller</i>', '</table>')
  78.         self.cast = re.sub('(\n|\t| )', '', self.cast)
  79.         self.cast = string.replace(self.cast, '\t', '')
  80.         self.cast = string.replace(self.cast, 'class="Daten">', '>\n')
  81.         self.cast = string.strip(gutils.strip_tags(self.cast))
  82.         self.cast = string.replace(self.cast, '... ', _(' as '))
  83.         self.cast = gutils.clean(self.cast)
  84.  
  85.     def get_classification(self):
  86.         # from imdb
  87.         self.classification = gutils.trim(gutils.trim(self.imdb_page, 'Altersfreigabe:', '</div>'), 'Germany:', '&')
  88.  
  89.     def get_studio(self):
  90.         # from imdb
  91.         self.studio = gutils.trim(self.imdb_page, '<h5>Firma:</h5>', '</a>')
  92.  
  93.     def get_o_site(self):
  94.         self.o_site = ""
  95.  
  96.     def get_site(self):
  97.         self.site = self.url
  98.  
  99.     def get_trailer(self):
  100.         self.trailer = ""
  101.  
  102.     def get_country(self):
  103.         self.country = gutils.trim(self.page,"Herstellungsland:","</a>")
  104.  
  105.     def get_rating(self):
  106.         self.rating = gutils.trim(self.page,"<br>Note: "," ")
  107.         if self.rating == '':
  108.             self.rating = "0"
  109.         self.rating = str(round(float(self.rating)))
  110.  
  111.     def regextrim(self,text,key1,key2):
  112.         obj = re.search(key1, text)
  113.         if obj is None:
  114.             return ''
  115.         else:
  116.             p1 = obj.end()
  117.         obj = re.search(key2, text[p1:])
  118.         if obj is None:
  119.             return ''
  120.         else:
  121.             p2 = p1 + obj.start()
  122.         return text[p1:p2]
  123.  
  124. class SearchPlugin(movie.SearchMovie):
  125.     def __init__(self):
  126.         self.original_url_search   = "http://www.ofdb.de/view.php?page=suchergebnis&Kat=OTitel&SText="
  127.         self.translated_url_search = "http://www.ofdb.de/view.php?page=suchergebnis&Kat=DTitel&SText="
  128.         self.encode='utf-8'
  129.         self.remove_accents = False
  130.  
  131.     def search(self,parent_window):
  132.         self.open_search(parent_window)
  133.         self.page = gutils.trim(self.page,"</b><br><br>", "<br><br><br>");
  134.         self.page = string.replace( self.page, "'", '"' )
  135.         self.page = string.replace( self.page, '<font size="1">', '' )
  136.         self.page = string.replace( self.page, '</font>', '' )
  137.         return self.page
  138.  
  139.     def get_searches(self):
  140.         elements = string.split(self.page,"<br>")
  141.  
  142.         if (elements[0]<>''):
  143.             for element in elements:
  144.                 elementid = gutils.trim(element,'<a href="','"')
  145.                 if not elementid is None and not elementid == '':
  146.                     self.ids.append(elementid)
  147.                     elementname = gutils.clean(element)
  148.                     p1 = string.find(elementname, '>')
  149.                     if p1 == -1:
  150.                         self.titles.append(elementname)
  151.                     else:
  152.                         self.titles.append(elementname[p1+1:])
  153.  
  154. #
  155. # Plugin Test
  156. #
  157. class SearchPluginTest(SearchPlugin):
  158.     #
  159.     # Configuration for automated tests:
  160.     # dict { movie_id -> [ expected result count for original url, expected result count for translated url ] }
  161.     #
  162.     test_configuration = {
  163.         'Rocky Balboa'            : [ 1, 1 ],
  164.         'Arahan'                : [ 3, 2 ],
  165.         'gl├╝ckliches'            : [ 4, 2 ]
  166.     }
  167.  
  168. class PluginTest:
  169.     #
  170.     # Configuration for automated tests:
  171.     # dict { movie_id -> dict { arribute -> value } }
  172.     #
  173.     # value: * True/False if attribute only should be tested for any value
  174.     #        * or the expected value
  175.     #
  176.     test_configuration = {
  177.         'film/103013,Rocky%20Balboa' : { 
  178.             'title'             : 'Rocky Balboa',
  179.             'o_title'             : 'Rocky Balboa',
  180.             'director'            : 'Sylvester Stallone',
  181.             'plot'                 : True,
  182.             'cast'                : 'Sylvester Stallone' + _(' as ') + 'Rocky Balboa\n\
  183. Burt Young' + _(' as ') + 'Paulie\n\
  184. Milo Ventimiglia' + _(' as ') + 'Robert Jr.\n\
  185. Geraldine Hughes' + (' as ') + 'Marie\n\
  186. James Francis Kelly III\n\
  187. Tony Burton\n\
  188. A.J. Benza\n\
  189. Henry G. Sanders\n\
  190. Antonio Tarver' + (' as ') + 'Mason \'The Line\' Dixon\n\
  191. Pedro Lovell\n\
  192. Ana Gerena\n\
  193. Angela Boyd\n\
  194. Louis Giansante\n\
  195. Maureen Schilling\n\
  196. Carter Mitchell\n\
  197. Vinod Kumar\n\
  198. Tobias Segal\n\
  199. Tim Carr\n\
  200. Paul Dion Monte\n\
  201. Kevin King Templeton\n\
  202. Robert Michael Kelly\n\
  203. Don Sherman\n\
  204. Nick Baker\n\
  205. Rick Buchborn\n\
  206. Stu Nahan\n\
  207. Gary Compton\n\
  208. Jody Giambelluca\n\
  209. Frank Stallone\n\
  210. Fran Pultro\n\
  211. Michael Buffer as Ring Announcer\n\
  212. Jack Lazzarado\n\
  213. Marc Ratner\n\
  214. Anthony Lato Jr.\n\
  215. Yahya\n\
  216. Gunnar Peterson\n\
  217. Bernard Fern├índez\n\
  218. Bert Randolph Sugar\n\
  219. Jim Lampley\n\
  220. Larry Merchant\n\
  221. Max Kellerman\n\
  222. James Binns\n\
  223. Johnnie Hobbs Jr.\n\
  224. Barney Fitzpatrick\n\
  225. Brian Kenny\n\
  226. Dana Jacobson\n\
  227. Skip Bayless\n\
  228. Charles Johnson\n\
  229. Matt Frack\n\
  230. Woody Paige\n\
  231. Jay Crawford\n\
  232. Lahmard J. Tate\n\
  233. LeRoy Neiman\n\
  234. Mike Tyson' + _(' as ') + 'Himself\n\
  235. Lou DiBella\n\
  236. Joe Cortez\n\
  237. Ricky Cavazos',
  238.             'country'            : 'USA',
  239.             'genre'                : 'Action, Drama, Sportfilm',
  240.             'classification'    : False,
  241.             'studio'            : 'Metro-Goldwyn-Mayer (MGM)',
  242.             'o_site'            : False,
  243.             'site'                : 'http://www.ofdb.de/film/103013,Rocky%20Balboa',
  244.             'trailer'            : False,
  245.             'year'                : 2006,
  246.             'notes'                : False,
  247.             'runtime'            : 102,
  248.             'image'                : True,
  249.             'rating'            : 8
  250.         },
  251.         'film/22489,Ein-Gl%C3%BCckliches-Jahr' : { 
  252.             'title'             : 'Gl├╝ckliches Jahr, Ein',
  253.             'o_title'             : 'Bonne ann├⌐e, La',
  254.             'director'            : 'Claude Lelouch',
  255.             'plot'                 : False,
  256.             'cast'                : 'Lino Ventura\n\
  257. Fran├ºoise Fabian\n\
  258. Charles G├⌐rard\n\
  259. Andr├⌐ Falcon as Le bijoutier\n\
  260. Mireille Mathieu\n\
  261. Lilo\n\
  262. Claude Mann\n\
  263. Fr├⌐d├⌐ric de Pasquale\n\
  264. G├⌐rard Sire\n\
  265. Silvano Tranquilli\n\
  266. Andr├⌐ Barello\n\
  267. Michel Bertay\n\
  268. Norman de la Chesnaye\n\
  269. Pierre Edeline\n\
  270. Pierre Pontiche\n\
  271. Michou\n\
  272. Bettina Rheims\n\
  273. Joseph Rythmann\n\
  274. Georges Staquet\n\
  275. Jacques Villedieu\n\
  276. Harry Walter\n\
  277. Elie Chouraqui',
  278.             'country'            : 'Frankreich',
  279.             'genre'                : 'Kom├╢die, Krimi',
  280.             'classification'    : False,
  281.             'studio'            : 'Les Films 13',
  282.             'o_site'            : False,
  283.             'site'                : 'http://www.ofdb.de/film/22489,Ein-Gl%C3%BCckliches-Jahr',
  284.             'trailer'            : False,
  285.             'year'                : 1973,
  286.             'notes'                : False,
  287.             'runtime'            : 90,
  288.             'image'                : True,
  289.             'rating'            : 6
  290.         },
  291.         'film/54088,Arahan' : { 
  292.             'title'             : 'Arahan',
  293.             'o_title'             : 'Arahan jangpung daejakjeon',
  294.             'director'            : 'Ryoo Seung-wan',
  295.             'plot'                 : True,
  296.             'cast'                : 'Ryoo Seung-beom\n\
  297. Yoon Soy' + _(' as ') + 'Wi-jin\n\
  298. Ahn Sung-kee' + _(' as ') + 'Ja-woon\n\
  299. Jung Doo-hong' + _(' as ') + 'Heuk-Woon\n\
  300. Yun Ju-sang\n\
  301. Kim Ji-yeong\n\
  302. Baek Chan-gi\n\
  303. Kim Jae-man\n\
  304. Lee Dae-yeon\n\
  305. Kim Dong-ju\n\
  306. Kim Su-hyeon\n\
  307. Geum Dong-hyeon\n\
  308. Lee Jae-goo\n\
  309. Ahn Kil-kang\n\
  310. Bong Tae-gyu\n\
  311. Im Ha-ryong\n\
  312. Yoon Do-hyeon\n\
  313. Lee Choon-yeon',
  314.             'country'            : 'S├╝dkorea',
  315.             'genre'                : 'Action, Fantasy, Kom├╢die',
  316.             'classification'    : '16',
  317.             'studio'            : 'Fun and Happiness',
  318.             'o_site'            : False,
  319.             'site'                : 'http://www.ofdb.de/film/54088,Arahan',
  320.             'trailer'            : False,
  321.             'year'                : 2004,
  322.             'notes'                : False,
  323.             'runtime'            : 114,
  324.             'image'                : True,
  325.             'rating'            : 7
  326.         }
  327.     }
  328.